
from django_filters.rest_framework import FilterSet
from django_filters.filters import *

from django_filters.rest_framework import FilterSet


from apps.system.models import Dict, OperationRecord, LoginLog


class OperationRecordFilter(FilterSet):
    """
    OperationRecord过滤
    """
    add_time_begin = DateFilter(field_name="create_time",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="create_time",help_text="结束创建时间",lookup_expr="lte")
    company = CharFilter(field_name="user__company",help_text="公司名称",lookup_expr="exact")

    class Meta:
        model = OperationRecord
        fields = [
                  'company',
                  'request_method',
                  'url_name',
                  'add_time_begin','add_time_end',
                  ]

class LoginLogFilter(FilterSet):
    """
    LoginLog过滤
    """
    add_time_begin = DateFilter(field_name="timestamp", help_text="开始创建时间", lookup_expr="gte")
    add_time_end = DateFilter(field_name="timestamp", help_text="结束创建时间", lookup_expr="lte")
    company = CharFilter(field_name="user__company", help_text="公司名称", lookup_expr="exact")
    class Meta:
        model = LoginLog
        fields = [
            'company',
            'add_time_begin','add_time_end',
                  ]


class DictFilter(FilterSet):
    """
    Dict过滤
    """
    #根据系统名称查询
    sys_name= CharFilter(field_name="id",help_text="系统名称",lookup_expr="icontains")
    class Meta:
        model = Dict
        fields = ['sys_name']


__all__ =[
    'DictFilter',
]
